﻿Public Class MainForm

    Private aw As New AdventureLiteDataContext
    Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click
        Using awdc As New AdventureLiteDataContext
            Dim x = From c In awdc.Customers, o In c.Orders, oi In o.OrderItems _
                    Where c.FirstName.Length >= 5 And _
                    oi.ProductInformation.Name = "HL Road Frame - Red, 44" _
              Group By c Into avg = Average(oi.Quantity) _
              Let Name = c.FirstName & " " & c.LastName _
              Order By Name _
              Select New With {Name, .AverageOrder = avg}

            For Each y In x
                MsgBox(y.Name & " = " & y.AverageOrder)
            Next
        End Using

        'Load the customer for the UI
        Dim custs = From c In aw.Customers
        Me.CustomerBindingSource.DataSource = custs
    End Sub
End Class
